package com.hxm.appGenealogy.Function;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hxm.appGenealogy.config.queryVo.QueryWrapperVO;
import com.hxm.appGenealogy.entity.Comment;
import com.hxm.appGenealogy.mapper.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CommentFunction {

    @Autowired
    private CommentMapper commentMapper;


    public Comment selectByid(Long id) {
        return commentMapper.selectById(id);
    }

    public Comment insertDynamic(Comment comment) {
        commentMapper.insert(comment);
        return comment;
    }

    public void dedl(Comment comment) {
        commentMapper.deleteById(comment.getId());
    }

    public List<Comment> selectGetListQuery(String query) {
        QueryWrapper<Comment> queryWrapper = QueryWrapperVO.getQueryWrapper(query);
        List<Comment> dynamics = commentMapper.selectList(queryWrapper);
        return dynamics;
    }

    public Comment slectGetOneQuery(String query) {
        QueryWrapper<Comment> queryWrapper = QueryWrapperVO.getQueryWrapper(query);
        Comment dynamics = commentMapper.selectOne(queryWrapper);
        return dynamics;
    }

    /**
     * 分页查询;
     */
    public Page selectPage(Page page, String query) {
        QueryWrapper<Comment> queryWrapper = QueryWrapperVO.getQueryWrapper(query);
        Page page1 = commentMapper.selectPage(page, queryWrapper);
        return page1;
    }

    /**
     * 根据id修改数据;
     */
    public void updateByid(Comment comment) {
        commentMapper.updateById(comment);
    }
}
